package cn.easthome.demo.dao;

import cn.easthome.demo.bean.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

/**
 * IuserDaoImpl的实现类
 */
public class UserDaoImpl implements IUserDao{

    @Override
    public List<User> findAll() {
        DataSource dataSource = JDBCUtil.getDataSource();
        QueryRunner runner = new QueryRunner(dataSource);
        String sql="select * from user";
        List<User> users=null;
        try{
            users=runner.query(sql,new BeanListHandler<User>(User.class));
        }catch (SQLException throwables)
            {
            throwables.printStackTrace();
        }
        //返回查询结果
        return users;
    }
}
